package com.chinatelecom.otms.circuitcheck.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;

public class JsonUtil {
    public static String readCircuitIdByJsonString(String sourceString) throws Exception {
        JSONObject jb = JSONObject.parseObject(sourceString);
        JSONObject resultData = jb.getJSONObject("resultData");
        JSONArray dataArray = resultData.getJSONArray("data");
        if(dataArray.size() == 0){
            throw new Exception("不完整");
        }
        JSONObject jsonObject = dataArray.getJSONObject(0);
        return (String) jsonObject.get("circuitId");
    }

    public static String readResultDataByJsonString(String sourceString){
        JSONObject jsonObject = JSONObject.parseObject(sourceString, Feature.OrderedField, Feature.IgnoreNotMatch);
        JSONArray resultData = jsonObject.getJSONArray("resultData");
        return resultData.toJSONString();
    }
}
